#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repb(i,n) for(int i=n-1; i>=0; i--)
#define REP(i,a,b) for(int i=a; i<=b; i++)
#define REPB(i,a,b) for(int i=a; i>=b; i--)
#define pb push_back
#define mp make_pair
#define tc(t) int t; cin>>t; while(t--)

int main()
{
	//#ifndef LOCAL
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	//#endif
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	tc(t)
	{
		int n;
		cin>>n;
		int a[200005];
		rep(i,n) cin>>a[i];
		int ans=0;
		if(n<=15)
		{
			for(long long i=0; i<(1<<(n)); i++)
			{
				//cerr<<"i="<<i<<":\n";
				int r=-1,b=-1,pts=0;
				rep(j,n)
				{
					bool c=i&(1ll<<j);
					//cerr<<"\tc="<<c<<", r="<<r<<", b="<<b<<endl;
					if(c)
					{
						if(a[j]==r) pts+=a[j];
						r=a[j];
					}
					else
					{
						if(a[j]==b) pts+=a[j];
						b=a[j];
					}
				}
				ans=max(ans,pts);
			}
			cout<<ans<<endl;
		}
	}
	return 0;
}
